import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue';

export const columns: BasicColumn[] = [
  {
    title: '标题',
    dataIndex: 'title',
    width: 120,
    align: 'left',
  },
  {
    title: '唯一标识',
    dataIndex: 'name',
    width: 120,
    align: 'left',
  },
  {
    title: '图标',
    dataIndex: 'icon',
    width: 50,
    customRender: ({ record }) => {
      return h(Icon, { icon: record.icon });
    },
  },
  {
    title: '权限',
    dataIndex: 'permissions',
    width: 150,
  },
  {
    title: 'path',
    dataIndex: 'path',
    width: 100,
  },
  {
    title: '组件',
    dataIndex: 'component',
    width: 100,
  },
  {
    title: '排序',
    dataIndex: 'orderNo',
    width: 50,
  },
  {
    title: '状态',
    dataIndex: 'enable',
    width: 80,
    customRender: ({ record }) => {
      const color = record.enable ? 'green' : 'red';
      const text = record.enable ? '启用' : '停用';
      return h(Tag, { color: color }, () => text);
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'title',
    label: '标题',
    component: 'Input',
    required: true,
  },
  {
    field: 'name',
    label: '唯一标识',
    component: 'Input',
    required: true,
  },
  {
    field: 'parent',
    label: '上级菜单',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'title',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'orderNo',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'icon',
    label: '图标',
    component: 'IconPicker',
    required: false,
  },
  {
    field: 'path',
    label: 'path',
    component: 'Input',
    required: true,
  },
  {
    field: 'component',
    label: '组件路径',
    component: 'Input',
  },
  {
    field: 'permissions',
    label: '权限',
    component: 'Select',
    componentProps: {
      mode: 'multiple',
      options: [],
      fieldNames: {
        label: 'name',
        value: 'code',
      },
    },
  },
  {
    field: 'enable',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: true,
    componentProps: {
      options: [
        { label: '启用', value: true },
        { label: '禁用', value: false },
      ],
    },
  },
  {
    field: 'hideMenu',
    label: '是否显示',
    component: 'RadioButtonGroup',
    defaultValue: false,
    componentProps: {
      options: [
        { label: '是', value: false },
        { label: '否', value: true },
      ],
    },
  },
];
